package XML;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class produts {

	public static void main(String[] args) throws Exception {

		SAXReader reader = new SAXReader();
		Document doc = reader.read(new File("produts.xml"));
		Element root = doc.getRootElement();
		List<Element> list = doc.selectNodes("/shop/product");
		List<Product> list1 = new ArrayList<Product>();
		for (Element e : list) {
			String factoryadd = e.attributeValue("factoryaddr");
			boolean discount = Boolean.valueOf(e.attributeValue("dicount"));
			long itemno = Long.valueOf(e.selectSingleNode("itemno").getText());
			String name = e.selectSingleNode("name").getText();
			String unit = e.selectSingleNode("unit").getText();
			double price = Double.valueOf(e.selectSingleNode("price").getText());
			int stockcount = Integer.valueOf(e.selectSingleNode("stockcount").getText());

			Product pro = new Product(itemno, factoryadd, name, unit, price, stockcount, discount);
			list1.add(pro);
		}
		for (Product p : list1) {
			System.out.println(p);
		}
	}
}